<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
File System
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot126.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot124.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot128.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc281">20.3</A>&nbsp;&nbsp;File System</H2><UL>
<LI><A HREF="umsroot127.html#toc156">Current Directory</A>
<LI><A HREF="umsroot127.html#toc157">Looking at Directories</A>
<LI><A HREF="umsroot127.html#toc158">Checking Files</A>
<LI><A HREF="umsroot127.html#toc159">Renaming and Removing Files</A>
<LI><A HREF="umsroot127.html#toc160">Filenames</A>
</UL>

A number of built-in predicates is provided for dealing with files and
directories.
Here we consider only the file as a whole, for opening files and accessing
their contents refer to chapter <A HREF="umsroot057.html#chapio">10</A>.<BR>
<BR>
<A NAME="toc156"></A>
<H3 CLASS="subsection"><A NAME="htoc282">20.3.1</A>&nbsp;&nbsp;Current Directory</H3>
The current working directory is an important notion in UNIX.
It can be read and changed within the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> system by using <A HREF="../bips/kernel/opsys/getcwd-1.html"><B>getcwd/1</B></A><A NAME="@default1120"></A> and
<A HREF="../bips/kernel/opsys/cd-1.html"><B>cd/1</B></A><A NAME="@default1121"></A> respectively.
<A NAME="@default1122"></A>
<A NAME="@default1123"></A>
The current working directory is accessible as a global flag as well.
Reading and writing this flag is equivalent to the use of <A HREF="../bips/kernel/opsys/getcwd-1.html"><B>getcwd/1</B></A><A NAME="@default1124"></A> and
<A HREF="../bips/kernel/opsys/cd-1.html"><B>cd/1</B></A><A NAME="@default1125"></A>:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: getcwd(Where).

Where = "/usr/name/prolog"
yes.
[eclipse 2]: cd(..).

yes.
[eclipse 3]: get_flag(cwd, Where)

Where = "/usr/name"
yes.
</PRE></BLOCKQUOTE>
All ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> built-ins that take file names as arguments accept absolute
pathnames as well as relative pathnames starting at the current directory.<BR>
<BR>
<A NAME="toc157"></A>
<H3 CLASS="subsection"><A NAME="htoc283">20.3.2</A>&nbsp;&nbsp;Looking at Directories</H3>
To look at the contents of a directory, <A HREF="../bips/kernel/opsys/read_directory-4.html"><B>read_directory/4</B></A><A NAME="@default1126"></A> is available.
<A NAME="@default1127"></A>
It takes a directory pathname and a filename pattern and returns a list
of subdirectories and a list of files matching the pattern.
The following metacharacters are recognised in the pattern:
* matches an arbitrary sequence of characters,
? matches any single character, [] matches one of the
characters inside the brackets unless the first one is a in which case it matches any character but those inside the brackets.
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: read_directory("/usr/john", "*", Dirlist, Filelist).
Dirlist = ["subdir1", "subdir2"]
Filelist = ["one.c", "two.c", "three.pl", "four.pl"]
yes.
</PRE></BLOCKQUOTE>
<A NAME="toc158"></A>
<H3 CLASS="subsection"><A NAME="htoc284">20.3.3</A>&nbsp;&nbsp;Checking Files</H3>
For checking the existence of files,
<A HREF="../bips/kernel/opsys/exists-1.html"><B>exists/1</B></A><A NAME="@default1128"></A> or the more powerful
<A HREF="../bips/kernel/opsys/existing_file-4.html"><B>existing_file/4</B></A><A NAME="@default1129"></A> is used.
<A NAME="@default1130"></A>
<A NAME="@default1131"></A>
For accessing any file properties there is <A HREF="../bips/kernel/opsys/get_file_info-3.html"><B>get_file_info/3</B></A><A NAME="@default1132"></A>.
<A NAME="@default1133"></A>
It can return file permissions, type, owner, size, inode, number of
links as well as creation, access and modification times
(as defined by the UNIX system call <I>stat(2)</I>; not all entries are
meaningful under Windows), and accessibility
information.
It fails when the specified file does not exist.
<A NAME="@default1134"></A>
Refer to the reference manual or <A HREF="../bips/kernel/env/help-1.html"><B>help/1</B></A><A NAME="@default1135"></A> for details.<BR>
<BR>
<A NAME="toc159"></A>
<H3 CLASS="subsection"><A NAME="htoc285">20.3.4</A>&nbsp;&nbsp;Renaming and Removing Files</H3>
For these basic operations with files, <A HREF="../bips/kernel/opsys/rename-2.html"><B>rename/2</B></A><A NAME="@default1136"></A> and <A HREF="../bips/kernel/opsys/delete-1.html"><B>delete/1</B></A><A NAME="@default1137"></A>
are provided.
<A NAME="@default1138"></A>
<A NAME="@default1139"></A><BR>
<BR>
<A NAME="toc160"></A>
<H3 CLASS="subsection"><A NAME="htoc286">20.3.5</A>&nbsp;&nbsp;Filenames</H3>
The filenames used by ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> is in the Unix format, including on Window
platforms, with the addition that the disk such as <CODE>C:</CODE> is
indicated by <CODE>//C/</CODE>, so a Windows filename such as
<CODE>"C:\my\path\name.ecl"</CODE> should be writen as
<CODE>"//C/my/path/name.pl"</CODE>. The utility <A HREF="../bips/kernel/opsys/os_file_name-2.html"><B>os_file_name/2</B></A><A NAME="@default1140"></A> provides for
the interconversion between the format used in ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> and the Operating
Systems' format. <BR>
<BR>
The utility <A HREF="../bips/kernel/opsys/pathname-4.html"><B>pathname/4</B></A><A NAME="@default1141"></A>
is provided to ease the handling of filenames.
<A NAME="@default1142"></A>
It takes a full pathname and cuts it into the directory
pathname, the filename proper and a suffix (
the part beginning with the last dot in the string).
It also expands symbolic pathnames, starting with <CODE>~</CODE>, <CODE>~</CODE>user
or $var.
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: Name = "~octopus/prolog/file.pl",
        pathname(Name, Path, File, Suffix).

Path = "/usr/octopus/prolog/"
File = "file.pl"
Name = "~octopus/prolog/file.pl"
Suffix = ".pl"
yes.
</PRE></BLOCKQUOTE>
<HR>
<A HREF="umsroot126.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot124.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot128.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
